package transcoding

import (
	"gitee.com/mootok/mootok/src/constant/config"
	"github.com/qiniu/go-sdk/v7/auth/qbox"
	"github.com/qiniu/go-sdk/v7/storage"
)

type QiniuService struct {
	mac *qbox.Mac
}


func (f *QiniuService) CreateTranscodingTask(fileName string, fops string) (persistentID string, err error){
	cfg := storage.Config{
		UseHTTPS: true,
	}
	operationManager := storage.NewOperationManager(f.mac, &cfg)
	//不需要回调
	persistentID, err = operationManager.Pfop(config.EnvConfig.QiNiuKodoBucket, fileName, fops, "", "", false)

	if err != nil {
		return
	}
	return
}

func  (f *QiniuService) QueryTranscodingProgress(persistentID string) (Status, error){
	cfg := storage.Config{
		UseHTTPS: true,
	}
	operationManager := storage.NewOperationManager(f.mac, &cfg)

	ret, err := operationManager.Prefop(persistentID)
	if err != nil {
		return StatusFailed, err
	}
	// 状态码0成功，1等待处理，2正在处理，3处理失败。
	if ret.Code == 0 {
		return StatusFinished, nil
	}
	if ret.Code == 1 {
		return StatusWaiting, nil
	}
	if ret.Code == 2 {
		return StatusDoing, nil
	}
	return StatusFailed, nil
}
